package com.xh.bussiness.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.bussiness.system.bean.request.ConfigRequest;
import com.xh.bussiness.system.model.Config;
import com.xh.bussiness.system.dao.ConfigMapper;
import com.xh.bussiness.system.service.IConfigService;
import com.xh.core.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import com.xh.core.bean.XhPage;
import com.xh.core.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jqm
 * @since 2021-02-04
 */
@Service
public class ConfigServiceImpl extends BaseServiceImpl<ConfigMapper, Config> implements IConfigService {
    @Override
    public XhPage queryConfigPage(XhPage page, ConfigRequest bean) {
        QueryWrapper qw=new QueryWrapper<Config>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryConfig(ConfigRequest bean) {
        QueryWrapper qw=new QueryWrapper<Config>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public Config queryByModuleCode(String prepare_check) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("module_code",prepare_check);
        return super.selectFirst(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(ConfigRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        return qw;
    }
}
